import { Operator } from './interface'
import BaseInput from './components/BaseInput'
import TagsInput from './components/TagsInput'
import RangeInput from './components/RangeInput'

export const components = {
    input: BaseInput,
    tags: TagsInput,
    range: RangeInput,
}

export enum OperatorKey {
    eq,
    neq,
    in,
    nin,
    gt,
    gte,
    lt,
    lte,
    inner,
    outer,
    include,
    exclude,
    exist,
    nexist,
}
export const operator_map: Record<OperatorKey, Operator> = {
    [OperatorKey.eq]: { key: OperatorKey.eq, label: '=', title: '等于', component: components.input },
    [OperatorKey.neq]: { key: OperatorKey.neq, label: '≠', title: '不等于', component: components.input },
    [OperatorKey.in]: { key: OperatorKey.in, label: '∈', title: '属于', component: components.tags },
    [OperatorKey.nin]: { key: OperatorKey.nin, label: '∉', title: '不属于', component: components.tags },
    [OperatorKey.gt]: { key: OperatorKey.gt, label: '>', title: '大于', component: components.input },
    [OperatorKey.gte]: { key: OperatorKey.gte, label: '≥', title: '大于等于', component: components.input },
    [OperatorKey.lt]: { key: OperatorKey.lt, label: '<', title: '小于', component: components.input },
    [OperatorKey.lte]: { key: OperatorKey.lte, label: '≤', title: '小于等于', component: components.input },
    [OperatorKey.inner]: { key: OperatorKey.inner, label: '在范围内', title: '在范围内', component: components.range },
    [OperatorKey.outer]: { key: OperatorKey.outer, label: '不在范围', title: '不在范围', component: components.range },
    [OperatorKey.include]: { key: OperatorKey.include, label: '包含', title: '包含', component: components.input },
    [OperatorKey.exclude]: { key: OperatorKey.exclude, label: '不包含', title: '不包含', component: components.input },
    [OperatorKey.exist]: { key: OperatorKey.exist, label: '存在', title: '存在,值可能为空字符串' },
    [OperatorKey.nexist]: { key: OperatorKey.nexist, label: '不存在', title: '不存在' },
}

export const field_allow_operator = {
    string: [
        OperatorKey.eq,
        OperatorKey.neq,
        OperatorKey.in,
        OperatorKey.nin,
        OperatorKey.include,
        OperatorKey.exclude,
        OperatorKey.exist,
        OperatorKey.nexist,
    ],
    number: [
        OperatorKey.eq,
        OperatorKey.neq,
        OperatorKey.in,
        OperatorKey.nin,
        OperatorKey.gt,
        OperatorKey.gte,
        OperatorKey.lt,
        OperatorKey.lte,
        OperatorKey.inner,
        OperatorKey.outer,
        OperatorKey.exist,
        OperatorKey.nexist,
    ],
    array: [
        OperatorKey.include,
        OperatorKey.exclude,
        OperatorKey.exist,
        OperatorKey.nexist,
    ]
}